<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>固定资产使用列表</span>
      </div>
      <el-table
        v-loading="loading"
        :data="list"
        row-key="id"
        @row-dblclick="toDetail"
      >
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="code" label="固定资产编号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="名称" align="center">
        </el-table-column>
        <el-table-column prop="assetTypeName" label="类别" align="center">
        </el-table-column>
        <el-table-column
          prop="model"
          label="规格型号"
          align="center"
        ></el-table-column>
        <el-table-column prop="assetState" label="资产状态" align="center">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.asset_state"
              :value="scope.row.assetState"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="250px">
          <template slot-scope="scope">
            <el-button
              style="color: #f56c6c"
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="submitForm(scope.row)"
              >归还
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="queryParams.total > 0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { page, edit } from "@/api/prod/asset/account";

export default {
  name: "UseList",
  dicts: ["asset_state"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表格数据
      list: [],
      // 请求参数
      queryParams: {
        assetStateList: ["使用中"],
        pageNum: 1,
        pageSize: 10,
        // 总数
        total: 0,
      },
      // 选项
      options: [],
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询资产使用列表 */
    getList() {
      this.loading = true;
      page(this.queryParams).then((response) => {
        this.list = response.data;
        this.queryParams.total = response.info.total;
        this.loading = false;
      });
    },

    /** 跳转到列表页 */
    toDetail(row) {
      this.$router.push({
        path: "/asset/asset/account/detail",
        query: {
          id: row.id,
        },
      });
    },

    /** 归还按钮 */
    submitForm({ id }) {
      edit({ id }).then((response) => {
        this.$modal.msgSuccess("归还成功");
        this.getList();
      });
    },
  },
};
</script>

<style>
</style>